class Solution {
public:
    int numberOfWeakCharacters(vector<vector<int>>& properties) {
        sort(properties.begin(), properties.end(), [](const vector<int>& a, const vector<int>& b) {
            return a[0] != b[0] ? a[0] > b[0] : a[1] < b[1];
        });
        
        int maxDef = 0;
        int count = 0;
        
        for (auto& p : properties) {
            int currDef = p[1];
            if (currDef < maxDef) {
                count++;
            } else {
                maxDef = currDef;
            }
        }
        return count;
    }
};